package com.linux.huhx.thread3.singleDesign_1;

import java.util.concurrent.TimeUnit;

/**
 * @Author: huhx
 * @Date: 2017-10-31 下午 4:57
 */
public class MyObject3 {
    private static MyObject3 myObject;

    private MyObject3() {}

    public synchronized static MyObject3 getInstance() {
        try {
            if (myObject == null) {
                // 模拟一些准备的耗时操作
                TimeUnit.SECONDS.sleep(2);
                myObject = new MyObject3();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return myObject;
    }
}
